package com.wrial.kind.design;

import java.util.LinkedList;

public class BlockingQueue<E> {

    private LinkedList<E> list = new LinkedList<E>();
    public void put(E e) {
        synchronized (this) {
            list.add(e);
            this.notify();
        }
    }

    public E take() throws InterruptedException {
        synchronized (this) {
            while (list.size() == 0) {
                this.wait();
            }
            return list.removeFirst();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<Object> queue = new BlockingQueue<>();
        queue.put(1);
        queue.put(2);
        System.out.println(queue.take());
        System.out.println(queue.take());
        System.out.println(queue.take());

    }
}